package com.yrcm.eduapp.activity.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yrcm.eduapp.R;
import com.yrcm.eduapp.entity.AnswerEntity;

public class ZXDYAnswerAdapter extends BaseAdapter {
	private List<AnswerEntity> data;
	private Context mContext;
	private LayoutInflater inflater;

	public ZXDYAnswerAdapter(Context context, List<AnswerEntity> list) {
		this.mContext = context;
		this.data = list;
		this.inflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		// TODO Auto-generated method stub
		HolderView holder;
		if (view == null) {
			holder = new HolderView();
			view = inflater.inflate(R.layout.zxdy_home_daan_item, null);
			holder.nameTxt = (TextView) view.findViewById(R.id.dati_ren);
			holder.timeTxt = (TextView) view.findViewById(R.id.dati_shijian);
			holder.webCon = (WebView) view.findViewById(R.id.dati_neirong);

		} else {
			holder = (HolderView) view.getTag();
		}
		
		holder.nameTxt.setText(data.get(position).getCreater());
		holder.timeTxt.setText(data.get(position).getAnswerTime());

		holder.webCon.getSettings().setDefaultTextEncodingName("utf-8");
		holder.webCon.getSettings().setDefaultFontSize(24);
		holder.webCon.setBackgroundColor(0);
		holder.webCon.getBackground().setAlpha(255);
		holder.webCon.getSettings().setSupportZoom(false);
		holder.webCon.loadDataWithBaseURL(null,
				data.get(position).getContent(), "text/html", "utf-8", null);
		view.setTag(holder);
		return view;
	}

	class HolderView {
		TextView nameTxt;
		TextView timeTxt;
		WebView webCon;
	}

	@Override
	public boolean isEnabled(int position) {
		return false;
	}

}
